package util;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
public class MyBatisUtil {
    private static SqlSession session = null;
    private static SqlSessionFactory factory = null;
    static {
    	try {
			Reader reader = Resources.getResourceAsReader("mybatix-config.xml");
			factory = new SqlSessionFactoryBuilder().build(reader);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    public static SqlSession getSqlSession(SqlSession session){
    	session = factory.openSession();
    	return session;
    }
    public static void closeAll(){
    	session.close();
    }
}
